package br.cin.ufpe.corba.examples.navigator;


import java.awt.BorderLayout;

import javax.swing.JPanel;
import javax.swing.JTree;

import br.cin.ufpe.corba.ORB;
import br.cin.ufpe.corba.namingservice.NamingContextExt;
import br.cin.ufpe.corba.namingservice.binding.Binding;


public class NamingServiceTreePanel extends JPanel {

	private static final long serialVersionUID = -3726279866585168827L;
	
	private JTree tree;

    public NamingServiceTreePanel(ORB orb) {
        this( new NamingServiceModel(orb) );
    }

    public NamingServiceTreePanel( NamingContextExt startPath ) {
        this( new NamingServiceModel( startPath ) );
    }

    public NamingServiceTreePanel( NamingServiceModel model ) {
        tree = new JTree( model ) {       

			private static final long serialVersionUID = 1L;

			public String convertValueToText(Object value, boolean selected,
                                             boolean expanded, boolean leaf, int row,
                                             boolean hasFocus) {
                return ((Binding)value).getName().toString();
            }
        };

        //tree.setLargeModel( true );        
        tree.setRootVisible( false );
        tree.setShowsRootHandles( true );
        tree.putClientProperty( "JTree.lineStyle", "Angled" );

        setLayout( new BorderLayout() );
        add( tree, BorderLayout.CENTER );
    }

    public JTree getTree() {
       return tree;
    }
}


